package com.comtime.view;

import com.comtime.smartkilimanjaro.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class EditDialog extends Dialog implements View.OnClickListener {

	View view;
	TextView tv_title;
	EditText edit_content;
	Button btn_left, btn_right;
	RelativeLayout relative_area;
	View line_vertical;
	
	OnEditClickListener editClickListener;

	public EditDialog(Context context,OnEditClickListener onEditClickListener) {
		super(context, R.style.MyDialog);
		this.editClickListener=onEditClickListener;
		view = LayoutInflater.from(context).inflate(R.layout.dialog_edit, null);
		relative_area = (RelativeLayout) view.findViewById(R.id.relative_area);
		tv_title = (TextView) view.findViewById(R.id.text_title);
		edit_content = (EditText) view.findViewById(R.id.edit_content);
		edit_content.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
		btn_left = (Button) view.findViewById(R.id.btn_mydialog_left);
		btn_right = (Button) view.findViewById(R.id.btn_mydialog_right);
		line_vertical = view.findViewById(R.id.line_vertical);
		btn_left.setOnClickListener(this);
		btn_right.setOnClickListener(this);
		
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setCanceledOnTouchOutside(false);
		if (btn_right.getText() == null || btn_right.getText().equals("")) {
			btn_right.setVisibility(View.GONE);
			line_vertical.setVisibility(View.GONE);
		}

		tv_title.getPaint().setFakeBoldText(true);
		if (tv_title.getText().toString() == null
				|| tv_title.getText().toString().equals("")) {
			tv_title.setVisibility(View.GONE);
		}

		this.setContentView(view);
	}

	@Override
	public void setTitle(CharSequence title) {
		tv_title.setText(title);
	}

	/**
	 * setTitle
	 */
	@Override
	public void setTitle(int titleId) {
		tv_title.setText(titleId);

	}

	/**
	 * 
	 * @param content
	 *            dddd
	 */
	public void setContent(CharSequence content) {
		edit_content.setText(content);
	}

	/**
	 * 
	 * @param contentId
	 */
	public void setContent(int contentId) {
		edit_content.setText(contentId);
	}

	/**
	 * 
	 * @param text
	 */
	public void setLeftButtonText(CharSequence text) {
		btn_left.setText(text);
	}

	public void setLeftButtonText(int textid) {
		btn_left.setText(textid);
	}

	/**
	 * 
	 * @param text
	 */
	public void setRightButtonText(CharSequence text) {
		btn_right.setText(text);
	}

	public void setRightButtonText(int textid) {
		btn_right.setText(textid);
	}

	/**
	 * 
	 * @return
	 */
	public Button getLeftButton() {
		return btn_left;
	}

	/**
	 * 
	 * @return
	 */
	public Button getRighrButton() {
		return btn_right;
	}

	public interface OnEditClickListener {
		void onOkFeedBack(String str);

		void onCancelFeedBack();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_mydialog_left:
			
			editClickListener.onCancelFeedBack();
			dismiss();
			break;
		case R.id.btn_mydialog_right:
			
			editClickListener.onOkFeedBack(edit_content.getText().toString().replace(" ", ""));
			dismiss();
			break;

		default:
			break;
		}
	}
}
